<%-- 
    Document   : changePassword
    Created on : Mar 2, 2012, 9:10:43 AM
    Author     : Remy
--%>
<%@page import="java.sql.ResultSet"%>
<%@page import="Model.ProductManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%

    String loginAttempt = request.getParameter("loginAttempt");
    if (loginAttempt != null) {
        boolean isValid = true;

        if (loginAttempt.indexOf("<") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf(">") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("\"") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("/") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf(":") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf(";") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("=") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("|") > -1) {
            isValid = false;
        }

        if (isValid == false) {
            loginAttempt = null;
        }
               }
     String valid = request.getParameter("valid");
    if (loginAttempt != null) {
        boolean isValidMax = true;

        if (valid.indexOf("<") > -1) {
            isValidMax = false;
        } else if (valid.indexOf(">") > -1) {
            isValidMax = false;
        } else if (valid.indexOf("\"") > -1) {
            isValidMax = false;
        } else if (valid.indexOf("/") > -1) {
            isValidMax = false;
        } else if (valid.indexOf(":") > -1) {
            isValidMax = false;
        } else if (valid.indexOf(";") > -1) {
            isValidMax = false;
        } else if (valid.indexOf("=") > -1) {
            isValidMax = false;
        } else if (valid.indexOf("|") > -1) {
            isValidMax = false;
        }

        if (isValidMax == false) {
            valid = null;
        }
    }
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/foo.css" type="text/css"/>
        <link rel="stylesheet" type="text/css" href="css/superfish.css" media="screen">	
        <title>Foobar</title>
        <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="js/hoverIntent.js"></script>
        <script type="text/javascript" src="js/superfish.js"></script>
        <script type="text/javascript" src="js/changePasswordValidation.js"></script>
        <script type="text/javascript" src="js/SearchValidation.js"></script>
        <script type="text/javascript">

            // initialise plugins
            jQuery(function(){
                jQuery('ul.sf-menu').superfish();
            });
            
            function checkAuth(){
              if(<%=request.getParameter("loginAttempt")%>==false && isValid){
                 document.write('<span class="errLog">Authentication failed.</span>');
               }

            function validChange(){
              if(<%=request.getParameter("valid")%>==false && isValidMax){
                 document.write('<span class="erMes">The password you entered was incorrect.</span>');
               }                
            }
        </script>
    </head>
    <body class="bg">
          <script type="text/javascript">checkAuth();</script>
        <br/>
        <div class="hmenu">
            <% if (request.getSession(true).getAttribute("username") == null) {%>
           <p style="font-size: 12px; margin-top: -15px; float: right;">If you're not yet a member, sign up <a href="signUp.jsp">here!</a> </p>   
           <% }%>
           <img src="images/head.png" style="float: left; margin-left:20px;"/>
            <div class="log">
                
                <% if (request.getSession(true).getAttribute("username") != null) {%>
               <span>Hello <%=session.getAttribute("username")%>!</span><br>
                <span style="font-weight: normal; font-size: 10px;">You have <%=session.getAttribute("numCart")%> items in your cart.</span>
                <div id="nav">
                    <ul class="top">
                        <li><a href="viewCart.jsp">View Cart</a></li>
                        <li><a href="checkOut.jsp">Checkout</a></li>
                        <li><a href="viewProfile.jsp">Account Details</a></li>
                        <li><a href="LogoutServlet">Log out</a></li>
                    </ul>
                </div>
                <% } else {%>
                <span style="font-weight: bold;">Log in</span>
                <form method="post" action="LoginServlet">
                    <label>Username:</label><input type="text" name="username"/><br/>
                    <label>Password:</label><input type="password" name="password"/><br/>
                    <input type="submit" value="Log in" name="submit"/>
                </form>
                <% }%>
            </div>
            <ul class="sf-menu">
                <li class="current">
                    <a href="index.jsp">Home</a>
                </li>
                <li>
                    <a href="#">Products</a>
                    <ul>
                                        <%
                ResultSet rs = new ProductManager().getProductTypes();
                while(rs.next()){
                %>
                        <li>
                            <a href="products.jsp?prd=<%=rs.getInt("ProductTypeID")%>"><%=rs.getString("ProductType")%></a>
                        </li>
                <%}%>
                    </ul>
                </li>
                <li>
                    <a href="#">Stores</a>
                </li>
                <li>
                    <a href="#">Contact Us</a>
                </li>
                <li>
                    <form action="results.jsp">
                            <input type="text" name="search" placeholder="Enter your search"/>
                            <button type="submit" onClick="return SearchValidation(this.form);">Go</button>
                    </form>
                </li>
            </ul>
        </div>
        <div class="content">
            <form name="changepass" method="post" action="CustomerChangePassword">
            <h3>CHANGE PASSWORD</h3>
            <br/>
            Current Password: <input type="password" name="currpass"/>
            <br/>
            <script type="text/javascript">validChange();</script>
            <span class="erMes" id="errorcurrent"></span><br/>
            <br/>
            New Password:  <input type="password" name="newpass1"/>
            <br/>
            Re-type New Password: <input type="password" name="newpass2"/>
            <br/>
            <span class="erMes" id="errorpassword"></span><br/>
            <button type="submit" name="signup" onClick="return validateAll(this.form);" 
                        style="float:right; margin-right: 150px;">Submit</button>
            </form>
        </div>
    </body>
</html>
